<?php
/**
 * MapService.php
 *
 * @copyright   2023 thingsworld.com.cn - All Rights Reserved
 * @link        http://thingsworld.com.cn/
 * @author      stiffer.chen <chenl@thingsworld.com.cn>
 * @created     2023-04-18 15:50:57
 * @modified    2023-04-18 15:50:57
 *
 */

namespace App\Services;

class MapService
{
    private $basicPath = '';

    public function __construct()
    {
        $this->basicPath = public_path('docs/');
    }

    public function china()
    {
        $file = $this->basicPath . 'china.json';
        return $this->getContent($file);
    }

    public function world()
    {
        $file = $this->basicPath . 'world.json';
        return $this->getContent($file);
    }

    private function getContent($file)
    {
        if (!is_file($file)) {
            throw new \Exception('JSON文件不存在');
        }
        $jsonString = file_get_contents($file);
        $jsonData = json_decode($jsonString, true);
        return $jsonData;
    }
}